{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<module 'dml.data' from 'dml/data.py'>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import dml.data as D\n",
    "import numpy as np\n",
    "reload(D)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "dframe = D.index_directory(\"/media/ejhumphrey/tiny/timbre_sim/features/cqts/\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "instruments = dframe.instrument.unique()\n",
    "note_numbers = dframe.note_number.unique()\n",
    "inst_notes = dframe.inst_note.unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(5000.0, 0.0)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Same instrument\n",
    "ihist = {i: (dframe.instrument == i).sum() for i in instruments}\n",
    "counts = np.array(ihist.values())\n",
    "counts.mean(), counts.std()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1411.7647058823529, 1049.1014827495319)"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Same Pitch\n",
    "nhist = {nn: (dframe.note_number == nn).sum() for nn in sorted(note_numbers)}\n",
    "counts = np.array(nhist.values())\n",
    "counts.mean(), counts.std()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(119.76047904191617, 61.830901612233482)"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Same inst & pitch\n",
    "inhist = {inn: (dframe.inst_note == inn).sum() for inn in sorted(inst_notes)}\n",
    "counts = np.array(inhist.values())\n",
    "counts.mean(), counts.std()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(538.16621743036842, 254.41099151838688)"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Same inst & +/- delta pitch\n",
    "indhist = {}\n",
    "for i in instruments:\n",
    "    for nn in note_numbers:\n",
    "        key = \"{}_{}\".format(i, nn)\n",
    "        nidx = np.abs(dframe.note_number - nn) <= 2\n",
    "        iidx = (dframe.instrument == i)\n",
    "        c = (nidx & iidx).sum()\n",
    "        if c > 0:\n",
    "            indhist[key] = c\n",
    "\n",
    "counts = np.array(indhist.values())\n",
    "counts.mean(), counts.std()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
